package com.nananren.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import java.util.Date;
import java.util.Map;

public class JwtUtils {
    static String secrity = "wangshuai";
    static Date data = new Date(System.currentTimeMillis() + 3600 * 1000);

    // 获取jwt令牌
    public static String getJwt(Map<String, Object> claims) {
        String jwt = Jwts.builder()
                .signWith(SignatureAlgorithm.HS256, secrity)
                .setExpiration(data)
                .addClaims(claims)
                .compact();

        return jwt;
    }

    // 解析jwt令牌
    public static Map<String, Object> parseJwt(String jwt) {
        Claims body = Jwts.parser()
                .setSigningKey(secrity)
                .parseClaimsJws(jwt)
                .getBody();
        return body;
    }
}
